<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="Jama.Matrix" %>
<%@ page import="Database.KeywordVector" %>

<%@ include file="/header" %>

<%     
    response.setHeader("Cache-Control", "no-cache");
    
    Matrix freq = null;
    KeywordVector keywords = null;
    int i = 0;
    int j = 0;
    
    try
    {
        freq = (Matrix)request.getAttribute("matrix");
        keywords = (KeywordVector)request.getAttribute("keywords");
    }
    catch(Exception e)
    {
        response.sendRedirect(siteRoot+"/RebuildIndex");
    }
    
    if( freq == null
        || keywords == null)
    {
        response.sendRedirect(siteRoot+"/RebuildIndex");
    }
%>
    
<script language="javascript">
function checkUncheckAll(theElement)
{
    var theForm = theElement.form, z = 0;
    for(z=0; z<theForm.length;z++)
    {
        if(theForm[z].type == 'checkbox') // && theForm[z].name != 'checkall')
        {
            theForm[z].checked = theElement.checked;
        }
    }
}
</script>
<div id="indexForm">
    <p>Select desired keywords to take into account in the index's keywords list.</p>
    <form action="<%=siteRoot%>/RebuildIndex" method="post">
        <input type="hidden" name="sn" value="2" />
        <table>
            <tr>
                <td class="left">
                    <input type="checkbox" name="checkall" onclick="checkUncheckAll(this);" />select/unselect
                </td>
                <%
                    for(j=0; j<freq.getColumnDimension(); j++)
                    {
                %>
                <td>
                    Doc#<%=j%>
                </td>
                <%
                    }
                %>
            </tr>
            <%
                for(i=0; i<keywords.size(); i++)
                {
            %>
            <tr>
                <td class="left">
                    <input type="checkbox" name="keywords" value="<%=i%>" /><%=keywords.get(i).toString()%>
                </td>
                <%
                    for(j=0; j<freq.getColumnDimension(); j++)
                    {
                %>
                <td>
                    <%=freq.get(i,j)%>
                </td>
                <%
                    }
                %>
            </tr>
            <%
                }
            %>
            <tr>
                <td class="left">
                    <input type="checkbox" name="checkall" onclick="checkUncheckAll(this);" />select/unselect
                </td>
                <%
                    for(j=0; j<freq.getColumnDimension(); j++)
                    {
                %>
                <td>
                    Doc#<%=j%>
                </td>
                <%
                    }
                %>
            </tr>
        </table>
        <p><input type="image" id="indexSubmitIcon" src="<%=siteRoot%>/index/next.png" alt="Set desired keywords" title="Set desired keywords" /></p>
    </form>
</div>
    
<%@ include file="/footer" %>